﻿<%@ Page Title="" Language="C#" MasterPageFile="main.Master" AutoEventWireup="true" CodeBehind="series.aspx.cs" Inherits="comix.admininstration.series" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <h2>Σειρές</h2>
    <asp:ListView ID="ListView1" runat="server" DataKeyNames="ser_id" 
        DataSourceID="SqlDataSource1" InsertItemPosition="LastItem" 
        onitemdatabound="ListView1_ItemDataBound" 
        oniteminserting="ListView1_ItemInserting" 
        onitemupdating="ListView1_ItemUpdating" >
        <ItemTemplate>
            <tr style="">
                <td>
                    <asp:Label ID="pub_nameLabel" runat="server" Text='<%# Eval("ser_name") %>' />
                </td>
                <td>
                    <asp:DropDownList ID="DropDownList1" runat="server" Enabled="false"  DataSourceID="publishers" DataTextField="pub_name" DataValueField="pub_id">
                    </asp:DropDownList>
                </td>
                <td>
                    <asp:DropDownList ID="DropDownList2" runat="server"  Enabled="false" DataSourceID="categories" DataTextField="cat_name" DataValueField="cat_id">
                    </asp:DropDownList>
                </td>
                <td>
                    <asp:DropDownList ID="DropDownList3" runat="server"  Enabled="false" DataSourceID="parental" DataTextField="par_description" DataValueField="par_id">
                    </asp:DropDownList>
                </td>                                
                <td>
                    <asp:LinkButton ID="DeleteButton" runat="server" CommandName="Delete" 
                        Text="Διαγραφή" />
                    <asp:LinkButton ID="EditButton" runat="server" CommandName="Edit" Text="Επεξεργασία" />
                </td>                
            </tr>
        </ItemTemplate>
        <AlternatingItemTemplate>
            <tr style="">
                <td>
                    <asp:Label ID="pub_nameLabel" runat="server" Text='<%# Eval("ser_name") %>' />
                </td>
                <td>
                    <asp:DropDownList ID="DropDownList1" runat="server" Enabled="false" DataSourceID="publishers" DataTextField="pub_name" DataValueField="pub_id">
                    </asp:DropDownList>
                </td>
                <td>
                    <asp:DropDownList ID="DropDownList2" runat="server" Enabled="false" DataSourceID="categories" DataTextField="cat_name" DataValueField="cat_id">
                    </asp:DropDownList>
                </td>
                <td>
                    <asp:DropDownList ID="DropDownList3" runat="server" Enabled="false" DataSourceID="parental" DataTextField="par_description" DataValueField="par_id">
                    </asp:DropDownList>
                </td>                
                <td>
                    <asp:LinkButton ID="DeleteButton" runat="server" CommandName="Delete" 
                        Text="Διαγραφή" />
                    <asp:LinkButton ID="EditButton" runat="server" CommandName="Edit" Text="Επεξεργασία" />
                </td>                
            </tr>
        </AlternatingItemTemplate>
        <EmptyDataTemplate>
            <table id="Table1" runat="server" style="">
                <tr>
                    <td>
                        No data was returned.</td>
                </tr>
            </table>
        </EmptyDataTemplate>
        <InsertItemTemplate>
            <tr style="">
                <td>
                    <asp:TextBox ID="pub_nameTextBox" runat="server" 
                        Text='<%# Bind("ser_name") %>' />
                </td>
                <td>
                    <asp:DropDownList ID="DropDownList1" runat="server"  DataSourceID="publishers" DataTextField="pub_name" DataValueField="pub_id">
                    </asp:DropDownList>
                </td>
                <td>
                    <asp:DropDownList ID="DropDownList2" runat="server"  DataSourceID="categories" DataTextField="cat_name" DataValueField="cat_id">
                    </asp:DropDownList>
                </td>
                <td>
                    <asp:DropDownList ID="DropDownList3" runat="server"  DataSourceID="parental" DataTextField="par_description" DataValueField="par_id">
                    </asp:DropDownList>
                </td>                
                <td>
                    <asp:LinkButton ID="InsertButton" runat="server" CommandName="Insert" 
                        Text="Εισαγωγή" />
                </td>                
            </tr>
        </InsertItemTemplate>
        <LayoutTemplate>
            <table id="Table2" runat="server">
                <tr id="Tr1" runat="server">
                    <td id="Td1" runat="server">
                        <table ID="itemPlaceholderContainer" runat="server" border="0" style="">
                            <tr id="Tr2" runat="server" style="">
                                <th id="Th1" runat="server">
                                    Όνομα</th>
                                <th id="Th3" runat="server">
                                    Εκδότης</th>
                                <th id="Th4" runat="server">
                                    Κατηγορία</th>
                                <th id="Th5" runat="server">
                                    Καταλληλότητα</th>                                                                                                            
                                <th id="Th2" runat="server">
                                </th>                                                                        
                            </tr>
                            <tr ID="itemPlaceholder" runat="server">
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr id="Tr3" runat="server">
                    <td id="Td2" runat="server" style="">
                        <asp:DataPager ID="DataPager1" runat="server">
                            <Fields>
                                <asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="True" FirstPageText="<<"
                                    ShowNextPageButton="False" ShowPreviousPageButton="False" />
                                <asp:NumericPagerField />
                                <asp:NextPreviousPagerField ButtonType="Link" ShowLastPageButton="True" LastPageText=">>"
                                    ShowNextPageButton="False" ShowPreviousPageButton="False" />
                            </Fields>
                        </asp:DataPager>
                    </td>
                </tr>
            </table>
        </LayoutTemplate>
        <EditItemTemplate>
            <tr style="">
                <td>
                    <asp:TextBox ID="pub_nameTextBox" runat="server" 
                        Text='<%# Bind("ser_name") %>' />
                    <asp:Label ID="Label1" Visible="false" runat="server" Text='<%# Eval("ser_id") %>' />
                </td>
                <td>
                    <asp:DropDownList ID="DropDownList1" runat="server"  DataSourceID="publishers" DataTextField="pub_name" DataValueField="pub_id">
                    </asp:DropDownList>
                </td>
                <td>
                    <asp:DropDownList ID="DropDownList2" runat="server"  DataSourceID="categories" DataTextField="cat_name" DataValueField="cat_id">
                    </asp:DropDownList>
                </td>
                <td>
                    <asp:DropDownList ID="DropDownList3" runat="server"  DataSourceID="parental" DataTextField="par_description" DataValueField="par_id">
                    </asp:DropDownList>
                </td>                
                <td>
                    <asp:LinkButton ID="UpdateButton" runat="server" CommandName="Update" 
                        Text="Αποθήκευση" />
                    <asp:LinkButton ID="CancelButton" runat="server" CommandName="Cancel" 
                        Text="Άκυρο" />
                </td>                
            </tr>
            <tr valign="top"><td>Δημιουργοί:</td><td>
                <asp:ListBox ID="ListBox1" runat="server" Width="100%" SelectionMode="Multiple" DataSourceID="authors" DataTextField="aut_fullname" DataValueField="aut_id"></asp:ListBox>
            </td><td>Επιλεγμένοι:</td><td>
                <asp:ListBox ID="ListBox2" runat="server" Width="100%" SelectionMode="Multiple" DataSourceID="SqlDataSource2" DataTextField="aut_fullname" DataValueField="aut_id"></asp:ListBox>
            </td><td>
                <asp:LinkButton ID="LinkButton1" runat="server" OnCommand="InsertAuthors" CommandArgument='<%# Eval("ser_id") %>'>Εισαγωγή</asp:LinkButton>&nbsp;<asp:LinkButton ID="LinkButton2" runat="server" OnCommand="RemoveAuthors" CommandArgument='<%# Eval("ser_id") %>'>Διαγραφή</asp:LinkButton></td></tr>
            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:mainconectionstring %>" 
        SelectCommand="SELECT aut_id, ISNULL(aut_firstname,'') + ' ' + ISNULL(aut_midname,'') + ' ' + aut_lastname AS aut_fullname FROM AUTHORS INNER JOIN AUTHORS2SERIES ON aut_id = a2s_aut_id WHERE a2s_ser_id = @a2s_ser_id AND a2s_deleted = 0 ORDER BY aut_lastname, aut_firstname">
        <SelectParameters><asp:ControlParameter ControlID="Label1" Name="a2s_ser_id" PropertyName="Text" /></SelectParameters>
        </asp:SqlDataSource>
        </EditItemTemplate>
    </asp:ListView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:mainconectionstring %>" 
        DeleteCommand="UPDATE SERIES set ser_deleted = 1, ser_updatedate = getDate() WHERE ser_id = @ser_id" 
        InsertCommand="INSERT SERIES (ser_name,ser_pub_id,ser_par_id,ser_cat_id,ser_updatedate,ser_deleted) VALUES (@ser_name,@ser_pub_id,@ser_par_id,@ser_cat_id,getDate(),0)" 
        SelectCommand="SELECT ser_id, ser_name, ser_pub_id, ser_par_id, ser_cat_id FROM SERIES WHERE ser_deleted = 0 ORDER BY ser_name" 
        UpdateCommand="UPDATE SERIES SET ser_name = @ser_name, ser_pub_id = @ser_pub_id, ser_par_id = @ser_par_id, ser_cat_id = @ser_cat_id, ser_updatedate=getDate() WHERE ser_id = @ser_id">
        <DeleteParameters>
            <asp:Parameter Name="ser_id" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="ser_name" />
            <asp:Parameter Name="ser_id" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="ser_name" />
        </InsertParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="publishers" runat="server" 
        ConnectionString="<%$ ConnectionStrings:mainconectionstring %>" 
        SelectCommand="SELECT pub_id, pub_name FROM PUBLISHERS WHERE (pub_deleted = 0) ORDER BY pub_name">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="categories" runat="server" 
        ConnectionString="<%$ ConnectionStrings:mainconectionstring %>" 
        SelectCommand="SELECT cat_id, cat_name FROM CATEGORIES WHERE (cat_deleted = 0) ORDER BY cat_name">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="parental" runat="server" 
        ConnectionString="<%$ ConnectionStrings:mainconectionstring %>" 
        SelectCommand="SELECT par_id, par_description FROM PARENTAL WHERE (par_deleted = 0) ORDER BY par_description">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="authors" runat="server" 
        ConnectionString="<%$ ConnectionStrings:mainconectionstring %>" 
        
        SelectCommand="SELECT aut_id,  (ISNULL(aut_firstname,'')  +' ' +ISNULL(aut_midname,'')+' '+ aut_lastname) as aut_fullname  FROM AUTHORS WHERE aut_deleted = 0 ORDER BY aut_lastname, aut_firstname">
    </asp:SqlDataSource>
</asp:Content>
